package com.danskin.wechat.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.context.web.WebAppConfiguration;

import com.danskin.wechat.dao.ActivityApplyConfigDao;
import com.danskin.wechat.dao.ActivityApplyDao;
import com.danskin.wechat.dao.VipOptionDao;
import com.danskin.wechat.dao.VipVoteDao;
import com.danskin.wechat.entity.ActivityApply;
import com.danskin.wechat.entity.ActivityApplyConfig;
import com.danskin.wechat.entity.ActivityApplyConfigOption;
import com.danskin.wechat.entity.VipOption;
import com.danskin.wechat.entity.VipVote;
import com.danskin.wechat.entity.example.ActivityApplyConfigExample;
import com.danskin.wechat.entity.example.ActivityApplyConfigExample.Criteria;
import com.danskin.wechat.entity.example.ActivityApplyExample;
import com.danskin.wechat.service.ActivityApplyService;

@Service
public class ActivityApplyServiceImpl implements ActivityApplyService{
	@Autowired
	private ActivityApplyDao activityApplyDao;
	
	@Autowired 
	private ActivityApplyConfigDao activityApplyConfigDao;
	
	@Autowired
	private VipVoteDao vipVoteDao;
	
	@Autowired
	private VipOptionDao vipOptionDao;

	@Override
	public List<ActivityApply> queryActivityApplyName(String id) {
		// TODO Auto-generated method stub
		return activityApplyDao.queryActivityApplyName(id);
	}

	@Override
	public List<ActivityApplyConfigOption> queryActivityApplyConfigOption() {
		// TODO Auto-generated method stub
		return activityApplyDao.queryActivityApplyConfigOption();
	}

	@Override
	public List<ActivityApply> findactivityApply(String id) {
		// TODO Auto-generated method stub
		return activityApplyDao.findactivityApply(id);
	}

	@Override
	public List<ActivityApplyConfig> getAllActivityApplyConfig() {
		ActivityApplyConfigExample example=new ActivityApplyConfigExample();
		Criteria criteria = example.createCriteria();
		criteria.andCodeIsNotNull();
		List<ActivityApplyConfig> list = activityApplyConfigDao.selectByExample(example);
		return list;
	}

	
	/**
	 * 保存报名活动选项
	 */
	@Override
	public int saveActivityApply(ActivityApply apply) {
		int i=0;
		ActivityApplyExample example=new ActivityApplyExample();
		com.danskin.wechat.entity.example.ActivityApplyExample.Criteria criteria = example.createCriteria();
		criteria.andActivityIdEqualTo(apply.getActivityId());
		criteria.andApplyConfigCodeEqualTo(apply.getApplyConfigCode());
		List<ActivityApply> list = activityApplyDao.selectByExample(example);
		if(list.size()>0){
			 i = activityApplyDao.updateByExampleSelective(apply, example);
		}else{
			 i = activityApplyDao.insertSelective(apply);
		}
		
		
		return i;
	}

	@Override
	public int saveVipVoteSelective(VipVote vote) {
		int i = vipVoteDao.insertSelective(vote);
		return i;
	}

	@Override
	public int saveVipOptionSelective(VipOption option) {
		int i = vipOptionDao.insertSelective(option);
		return i;
	}

	@Override
	public int updateVipVoteSelective(VipVote vote) {
		int i = vipVoteDao.updateByPrimaryKeySelective(vote);
		return i;
	}

	@Override
	public int updateVipOptionSelective(VipOption option) {
		int i = vipOptionDao.updateByPrimaryKeySelective(option);
		return i;
	}
	//根据活动id 删除报名选项
	@Override
	public int deleteVipApplyByActivityId(Integer activityId) {
		ActivityApplyExample example=new ActivityApplyExample();
		com.danskin.wechat.entity.example.ActivityApplyExample.Criteria criteria = example.createCriteria();
		criteria.andActivityIdEqualTo(activityId);
		int i = activityApplyDao.deleteByExample(example);
		return i;
	}

	

}
